package com.battle.project.order.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class HeadersConfig {


    @Value("${battle.order.headers.queue1.name:order_headers_queue1}")
    private String queue1;
    @Value("${battle.order.headers.queue2.name:order_headers_queue2}")
    private String queue2;

    @Value("${battle.order.headers.exchange.name:order_headers_exchange}")
    private String headersExchange;

    @Bean
    public Queue queue1(){
        return new Queue(queue1);
    }
    @Bean
    public Queue queue2(){
        return new Queue(queue2);
    }

    @Bean
    public HeadersExchange headersExchange(){
        return new HeadersExchange(headersExchange);
    }

    @Bean
    public Binding queueN1Binding(){
        Map<String,Object> map = new HashMap<>();
        map.put("name","queueN1");
        map.put("age","1");
        return BindingBuilder.bind(queue1()).to(headersExchange()).whereAll(map).match();
    }

    @Bean
    public Binding queueN2Binding(){

        Map<String,Object> map = new HashMap<>();
        map.put("name","queueN2");
        map.put("age","1");
        return BindingBuilder.bind(queue2()).to(headersExchange()).whereAny(map).match();
    }


}
